//
//  walletViewController.m
//  FastRunDemo
//
//  Created by 苟亚明 on 16/9/22.
//  Copyright © 2016年 苟亚明. All rights reserved.
//

#import "walletViewController.h"
#import "myWalletView.h"
#import "myWalletCell.h"
#import "MBProgressHUD+MJ.h"
@interface walletViewController () <UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, strong) UITableView *tableView;
@end

@implementation walletViewController
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.hidden = YES;
    UIImage *image = [UIImage imageNamed:@"transparent-1"];
    [self.navigationController.navigationBar setBackgroundImage:image
                                                  forBarMetrics:UIBarMetricsDefault];
    [self.navigationController.navigationBar setShadowImage:image];
}
- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    
    self.navigationController.navigationBar.hidden = NO;
}
static NSString *const walletCellID = @"myWalletCellID";
- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"我的钱包";
    self.tableView = [[UITableView alloc]initWithFrame:self.view.bounds];
    
    [self.tableView registerNib:[UINib nibWithNibName:@"myWalletCell" bundle:nil] forCellReuseIdentifier:walletCellID];
    
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    self.tableView.rowHeight = 60;
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    
    self.navigationItem.leftBarButtonItem = [UIBarButtonItem itemWithImage:@"arrow_back" highImage:@"arrow_back" target:self action:@selector(leftBtnClick)];
    self.automaticallyAdjustsScrollViewInsets = NO;
    myWalletView *header = [[[NSBundle mainBundle]loadNibNamed:@"myWalletView" owner:nil options:nil]lastObject];
    header.height = 350;
    [header.btnBack addTarget:self action:@selector(leftBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [header.btnRecharge addTarget:self action:@selector(btnRechargeClick) forControlEvents:UIControlEventTouchUpInside];
    [header.btnWithdrawals addTarget:self action:@selector(btnWithdrawalsClick) forControlEvents:UIControlEventTouchUpInside];
    self.tableView.tableHeaderView = header;
    
    [self.view addSubview:self.tableView];
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 44;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *sectionHeaderView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, GYMScreenW, 44)];
    sectionHeaderView.backgroundColor = [UIColor whiteColor];
    
    // 标签名字
    UILabel *lblText = [[UILabel alloc]initWithFrame:CGRectMake(20, 10, GYMScreenW, 22)];
    lblText.text = @"消费记录";
    lblText.textColor = [UIColor orangeColor];
    lblText.font = [UIFont systemFontOfSize:15];
    lblText.textAlignment = NSTextAlignmentLeft;
    
    // 短线
    UIView *shortLine = [[UIView alloc]initWithFrame:CGRectMake(10, sectionHeaderView.height - 1, GYMScreenW - 25, 1)];
    shortLine.backgroundColor = [UIColor lightGrayColor];
    shortLine.alpha = 0.2;
    [sectionHeaderView addSubview:shortLine];
    [sectionHeaderView addSubview:lblText];
    
    return sectionHeaderView;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 8;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    myWalletCell *cell = [tableView dequeueReusableCellWithIdentifier:walletCellID];
    
    
    return cell;
}

- (void)btnWithdrawalsClick{
    [MBProgressHUD showError:@"你木有钱"];
}
- (void)btnRechargeClick{
    [MBProgressHUD showError:@"暂不能充值"];
}
- (void)leftBtnClick{
    [self.navigationController popViewControllerAnimated:YES];
}


- (void)viewDidDisappear:(BOOL)animated{
    [super viewDidDisappear:animated];
    
    [self.navigationController.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
    [self.navigationController.navigationBar setShadowImage:nil];
}

@end
